home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
system
/
log3.zip
/
LOG.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-05-09
|
16KB
|
417 lines
Program Log;
(****************************************************************************)
(* *)
(* LOG *)
(* Revision 2.0 *)
(* Written by Don Gancsos and Robert Wilcox *)
(* *)
(* A program which logs computer operation and calculates *)
(* the elapsed time between log entries. *)
(* Logs date, time, elapsed time and comment to the *)
(* file "TIME.LOG" *)
(* *)
(* Use: LOG comment *)
(* *)
(* Modified by R. Wilcox 3-14-86 *)
(* - Now puts log file in root directory of drive A *)
(* rather than in the logged-in directory. *)
(* - Uses command line (up to 50 characters) as comment. *)
(* - Log file changed to 'TIME.LOG' (3-23-86) *)
(* Rev 2.0 modifications 4-9-86 *)
(* - Uses random file allowing a "SHOW" program to *)
(* display start and end log entries with the *)
(* calculated elapsed time. *)
(* - Log file changed to 'NEWTIME.LOG'. *)
(* *)
(* Rev 3.0 modifications 5-10-87 by Rick Johnson *)
(* *)
(* Use: LOG <off|[comment] /a|/*> *)
(* *)
(* - Keeps log in random file 'TIME.LOG' in path *)
(* C:\UTILITY. *)
(* - Random file records now store: *)
(* 1) Time category, e.g. 'B' for business. *)
(* 2) Start date. *)
(* 3) Start time. *)
(* 4) End time. *)
(* 5) Elapsed time (string). *)
(* 6) Elapsed time (real no.). *)
(* 8) Comment (up to 12 characters). *)
(* - Session terminated and elapsed time calculated *)
(* with 'LOG OFF' command. *)
(* - Time category invoked with '/a' parameter where *)
(* 'a' is any alpha character a through z. *)
(* - Time categories 'B' and 'P' noted as 'Business' *)
(* or 'Personal' use in program's screen messages *)
(* - Times displayed and totaled with '/*' parameter *)
(* and optionally written to disk file: *)
(* 1) Text format for word processor or *)
(* 2) Comma-delimited for spreadsheet. *)
(* SHOW.COM no longer needed. *)
(* *)
(* *)
(****************************************************************************)
Type
Datestring = string[8];
CommandString = string[50];
CommentString = string[12];
Filename = string[24];
Registers = record
AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer;
End;
LogRec = Record
usage: char; {usage type, i.e. business/personal}
start_date_log : Datestring; {start date}
start_time_log : Datestring; {start time}
end_time_log : Datestring; {end time}
elapsed_log : Datestring; {elapsed time}
comment : CommentString; {comment}
elapsed_real : Real; {elapsed time stored as real no.}
end;
Var
Mon, Day, Year : string[2];
logfile : file of LogRec;
realtime : Real;
Buffer : CommandString;
CL : CommandString absolute cseg:$80;
log_data : logrec;
logoff : boolean;
Const
logfilename : filename = 'C:\UTILITY\TIME.LOG';
Function Date: Datestring;
var
RSet : Registers;
tempstring: Datestring;
i: Integer;
Begin
With Rset do
Begin
AX := $2A00; { DOS get date function }
MSDos(RSet);
CX := cx mod 100;
str(CX:2,year);
str(Hi(DX):2,mon);
str(Lo(DX):2,day);
End;
tempstring := mon + '/' + day + '/' + year;
for i := 1 to 8 do
if tempstring[i] = ' ' then
tempstring[i] := '0';
Date := tempstring;
End;
Function Time: Datestring;
var
RSet : registers;
hour, minute, second : string[2];
i : integer;
tempstring : Datestring;
Begin
rset.ax := $2C * 256;
MsDos(rset);
str((rset.cx div 256):2,hour);
str((rset.cx mod 256):2,minute);
str((rset.dx div 256):2,second);
tempstring := hour + ':' + minute + ':' + second;
for i := 1 to 8 do
if tempstring[i] = ' ' then
tempstring[i] := '0';
Time := tempstring;
End; {Time}
Function SecToString(secs: integer): Datestring;
var
t: integer;
result: Datestring;
tempresult: Datestring;
Begin
Str(secs div 3600:2,tempresult);
result := tempresult + ':';
t:= secs mod 3600;
Str(t div 60:2,tempresult);
result := result +tempresult + ':';
Str(t mod 60:2,tempresult);
result := result + tempresult;
For t := 1 to 8 do if result[t] = ' ' then result[t] := '0';
SecToString := result;
end;
Function elapsed_time(start_str, end_str: Datestring): Datestring;
var
i,j,k,starttime,endtime: integer;
begin
val(copy(end_str,1,2),i,j);
endtime := i * 3600;
val(copy(end_str,4,2),i,j);
endtime := endtime + (i * 60);
val(copy(end_str,7,2),i,j);
endtime := endtime + i;
val(copy(start_str,1,2),i,j);
starttime := i * 3600;
val(copy(start_str,4,2),i,j);
starttime := starttime + (i * 60);
val(copy(start_str,7,2),i,j);
starttime := starttime + i;
k := endtime - starttime;
elapsed_time := SecToString(k);
end;
Function elapsed_real_time(tempstring: Datestring): real;
var
temp, temptime : real;
err : integer;
begin
val(copy(tempstring,1,2),temptime,err); {get hours}
val(copy(tempstring,4,2),temp,err);
temptime := temptime + (temp/60); {get fraction of hours from minutes}
val(copy(tempstring,7,2),temp,err);
temptime := temptime + (temp/3600); {get fraction of hours from seconds}
elapsed_real_time := temptime;
end;
Procedure initialize_variables;
begin
logoff:=false;
log_data.usage := '@';
log_data.start_date_log:= Date;
log_data.start_time_log:= Time;
log_data.end_time_log:= Time;
log_data.elapsed_log:= '00:00:00';
log_data.comment:= '';
log_data.elapsed_real:=0;
end;
Function uppercase(tempstring: CommandString; startpos, number: integer): CommandString;
var temp : CommandString;
i : integer;
begin
if length(tempstring) >= startpos then
begin
tempstring:=copy(tempstring,startpos,number);
for i := 1 to length(tempstring) do
tempstring[i] := upcase(tempstring[i